import * as actionType from "./actionType"
import axios from 'axios'
import {fromJS} from 'immutable'

export const searchFocus = () => ({
  type: actionType.SEARCH_FOCUS
})

export const seachBlur = () => ({
  type: actionType.SEARCH_BLUR
})

export const changeList = (data) => ({
  type: actionType.INPUT_CHANGE,
  data: fromJS(data),
  totalPage: Math.ceil(data.length / 10)
})

export const changeMouse = () => ({
  type: actionType.MOUSE_ENTER
})

export const getList = () => {
  return (dispatch) => {
    axios.get('/api/headerlist.json').then((res) => {
      let data = res.data;
      console.log(data)
      dispatch(changeList(data.data))
    }).catch(() => {
      console.log("error")
    })
  }
}

export const mouseLeave = () => ({
  type: actionType.MOUSE_LEAVE
})

export const changePage = (page) => ({
  type: actionType.CHANGE_PAGE,
  page
})
